package alibaba.list;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author ChangLiang
 * @date 2021/3/12
 */
public class InitializeDemo {

    @Test
    @DisplayName("test")
    public void test(){
        // have a fixed size
        List<String> list = Arrays.asList("foo", "bar");
        // java.lang.UnsupportedOperationException
        list.add("aaa");
    }

    @Test
    @DisplayName("test")
    public void test2(){
        String[] array = {"foo", "bar"};
        List<String> list = Arrays.asList(array);
        array[0] = "baz";

        assertEquals("baz", list.get(0));
    }

    @Test
    @DisplayName("test")
    public void test3(){
        List<String> list = Stream.of("foo", "bar").collect(Collectors.toList());
        list.add("aaa");
    }

    @Test
    @DisplayName("test")
    public void test4() {
        List<String> cities = new ArrayList<String>() {
            {
                add("foo");
                add("bar");
            }
        };
    }
}
